package com.wgke.bluetooth.ui;

import android.annotation.SuppressLint;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.wgke.bluetooth.R;
import com.wgke.bluetooth.view.PressureMatrixRenderer;
import com.wgke.bluetooth.view.PressureMatrixRenderer2;

public class Chart1Activity extends AppCompatActivity {
    private GLSurfaceView glSurfaceView;
    private PressureMatrixRenderer2 renderer;
    private Button toggleViewButton;
    boolean is3DMode = true;

    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chart);

        // 创建GLSurfaceView实例
        glSurfaceView = findViewById(R.id.glSurfaceView);

        // 设置OpenGL版本为3.0
        glSurfaceView.setEGLContextClientVersion(2);

        // 创建并设置渲染器
        renderer = new PressureMatrixRenderer2();
        glSurfaceView.setRenderer(renderer);

        // 设置渲染模式为按需渲染，提高性能
        glSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

        // 切换2D/3D视图的按钮
        toggleViewButton = findViewById(R.id.toggleViewButton);
        toggleViewButton.setOnClickListener(v -> {
            is3DMode=!is3DMode;
            renderer.set3DMode(is3DMode);
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        glSurfaceView.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        glSurfaceView.onPause();
    }
}